package com.mystudy.dataStructure.collections;

import com.mystudy.dataStructure.link.LinkedList;

/**
 * @author 周志龙
 * @Email 15216876513@163.com
 * @Date on 2019/7/28 21:26
 * @Description 基于链表实现的集合
 */
public class LinkedListSet<E > implements Set<E> {
    private LinkedList<E> list;


    public LinkedListSet() {
        this.list = new LinkedList<>();
    }

    @Override
    public void add(E e) {
        //链表不能保证元素不能重复，所以要组合一下操作
        if(!contains(e)){
            //使用O(1)级别的添加
            list.addFirst(e);
        }
    }

    @Override
    public void remove(E e) {
        list.removeElement(e);
    }

    @Override
    public boolean contains(E e) {
        return list.contains(e);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public String toString() {
        return list.toString();
    }
}
